package com.web;

import java.util.List;

public class JDBCDemo {
    public static void main(String[] args) {
//        System.out.println("请输入:");
//        Scanner scanner = new Scanner(System.in);
//        String username=scanner.nextLine();
//        showStudent2(username);
        showStudent();
       if( login("zhangsan","123456"))
       {
           System.out.println("登录成功");
       }
       else {
           System.out.println("登录失败");
       }


    }
    public  static void showStudent(){
        List<Student> list = JBDCUtils.query(Student.class,"select*from student");
        for(Student s:list){
            System.out.println(s);
        }
//        try(Connection connection=DataSourceUtils.getConnection()) {
//            PreparedStatement ps=connection.prepareStatement("select *from student");
//            ResultSet rs=ps.executeQuery();
//            while (rs.next()){
//                int id=rs.getInt("id");
//                String name=rs.getString("name");
//                int age=rs.getInt("age");
//                System.out.println(id+" "+name+" "+age);
//            }
//
//        }catch (Exception e){
//            e.printStackTrace();
//        }
    }
    public static void showStudent2(String stuName){
        List<Student> list = JBDCUtils.query(Student.class,"select*from student where name like ?" ,"%"+stuName+"%");
        for(Student s:list){
            System.out.println(s);
        }

//        try(Connection connection=DataSourceUtils.getConnection()) {
//            PreparedStatement ps=connection.prepareStatement("select *from student where name like ?");
//            ps.setString(1, "%"+stuName+"%");
//            ResultSet rs=ps.executeQuery();
//            while (rs.next()){
//                int id=rs.getInt("id");
//                String name=rs.getString("name");
//                int age=rs.getInt("age");
//                System.out.println(id+" "+name+" "+age);
//            }
//
//        }catch (Exception e){
//            e.printStackTrace();
//        }
    }
    public static boolean login(String username,String password) {
        List<User> list = JBDCUtils.query(User.class, "select *from t_user where username=? and password=?", username, password);
        if (list.size() > 0) {
            return true;

        }
        return  false;
    }
}
